import QtQuick 2.2
import QtQuick.Controls 1.1
import "./"
import "./components/"
import "../javascript/Utils.js" as UtilsJS

import Utils 1.0

Flickable {
    property var titulo: "Preço Líder"
    property var subTitulo: null

    contentHeight: cards.height
    anchors.margins: 10

    property bool showMenuButton: true

    property Rectangle toolBarMenu: Rectangle {
        width: UtilsJS.dp2px(150)
        height: menuItems.height
        color: "#f3f3f3"

        Column {
            id: menuItems
            width: parent.width

            Button {
                text: "Info"
                style: applicationWindow.botoesDrawer
                width: parent.width
                height: UtilsJS.dp2px(48)
                property string icon: ""
                onClicked: {
                    applicationWindow.hideToolBarMenu();
                    applicationWindow.showPath();
                }
            }
        }
    }


    Column {
        id: cards
        width: parent.width
        spacing: 10

        Card {
            title: "DESEMPENHO:"
            CardDesempenho{id: cardDesempenho}
        }

        Card {
            id: cardAlerta
            title: "ALERTA(S):"
            CardAlerta{
                id: alertas
            }
        }

        Card {
            id: cardC
            title: "ÚLTIMOS PASSOS:"

            CardUltimosPassos{}
        }

    }

    Utils {
        id: utils
    }

    function showAlerts(alertsList) {
        var i,j;
        for(i=0; i<alertsList.length; i++) {
            var alert = alertsList[i];
            var index = alert.indexOf(":");

            alertas.show(alert.substring(0,index),alert.substring(index+1));
        }
    }

//    Timer {
//        id: timerMessages
//        interval: 1000
//        running: true
//        repeat: true
//        onTriggered: showAlerts(utils.getXMPPMessages());
//    }

    Connections {
        target: Qt.application
        onStateChanged: {
            switch (Qt.application.state) {
            case Qt.ApplicationSuspended:
            case Qt.ApplicationHidden:
//                timerMessages.running = false;
                break
            case Qt.ApplicationActive:
//                timerMessages.running = true;
                break
            }
       }
    }

    function doUpdate() {
        cardDesempenho.updateChart();
    }
}
